package com.deyuanyun.pic.docmger.controller;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.docmger.controller.dto.DocStandardDTO;
import com.deyuanyun.pic.docmger.controller.dto.DocStandardQueryVO;
import com.deyuanyun.pic.docmger.domain.DocStandard;
import com.deyuanyun.pic.docmger.service.DocStandardService;
import com.deyuanyun.pic.settings.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  文档中心---技术标准controller
 *  @author axiao(xj08.dream@gmail.com)
 *  @date 2016-11-14
 *  @version 1.0
 *  Histroy: [修改人][时间][描述]
 */
@Controller
@RequestMapping("/docmger/standard")
public class DocStandardController extends BaseController {

    @Autowired
    private DocStandardService docStandardService;

    /**
     * 跳转到技术标准页面
     * @param 
     * @return 
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-16
     */
    @RequestMapping("/toPage.html")
    public String toStandard() {
        return "/docCenter/technicalSt";
    }

    /**
     * 编辑技术标准
     * @param
     * @return
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-16
     */
    @RequestMapping("/editOrUpdate.html")
    public String editStandard(String id, Model model) {
        if(StringUtils.isNotEmpty(id)) {
            DocStandardDTO docStandard = docStandardService.selectById(id);
            model.addAttribute("standard", docStandard);
        }
        return "/docCenter/technicalStEdit";
    }

    /**
     * 查询技术标准列表，分页
     * @param queryVO
     * @return 
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-14
     */
    @RequestMapping("/search.json")
    @ResponseBody
    public void queryAll(DocStandardQueryVO queryVO) {
        PageJsonBean jsonBean = new PageJsonBean();
        jsonBean.setList(docStandardService.queryStandard(queryVO));
        AjaxSupport.sendSuccessText("success", jsonBean);
    }
    
    /**
     * 根据id删除技术标准
     * @param id
     * @return
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-14
     */
    @RequestMapping("/delete.json")
    @ResponseBody
    public void deleteStandard(@RequestParam("id") String id) {
        docStandardService.deleteStandardInfo(id);
        AjaxSupport.sendSuccessText("success", "删除成功！");
    }

    /**
     * 根据id更新技术标准信息
     * @param docStandard
     * @param attachmentId 附件id
     * @return
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-14
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public void updateStandardInfo(DocStandard docStandard, String attachmentId ) {
        docStandardService.updateStandardInfo(docStandard, attachmentId);
        AjaxSupport.sendSuccessText("success", "更新成功！");
    }

    /**
     * 新增技术标准信息
     * @param docStandard
     * @param attachmentId 附件id
     * @return
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-14
     */
    @RequestMapping("/add.json")
    @ResponseBody
    public void addStandardInfo(DocStandard docStandard, String attachmentId) {
        docStandardService.addStandardInfo(docStandard, attachmentId);
        AjaxSupport.sendSuccessText("success", "更新成功！");
    }
}
